package com.woniu.zhoukao.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.zhoukao.entity.Product;
import com.woniu.zhoukao.service.ProductService;
import com.woniu.zhoukao.vo.EsProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuao
 * @since 2023-02-07 09:47:31
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    ProductService productService;

    @RequestMapping("pageData")
    public Page<Product> pageData(Integer currentPage, Integer pageSize){

        Page<Product> pageData = productService.pageData(currentPage, pageSize);

        return pageData;
    }
    @RequestMapping("search")
    public Page<Product> search(Integer currentPage, Integer pageSize, String keyword){

        Page<Product> searchResult = productService.search(currentPage, pageSize, keyword);

        return searchResult;
    }

    @RequestMapping("toSearch")
    public String toSearch(String keyword, Model model){

        model.addAttribute("keyword",keyword);

        return "search";
    }
    @RequestMapping("searchBookBySql")
    @ResponseBody
    public Page<Product> searchBookBySql( Integer currentPage, Integer pageSize, String keyword){

        Page<Product> searchResult = productService.searchBookBySql(currentPage, pageSize, keyword);

        return searchResult;
    }

    @RequestMapping("searchBookByES")
    @ResponseBody
    public Page<EsProduct> searchBookByES(Integer currentPage, Integer pageSize, String keyword){

        Page<EsProduct> bookPage = productService.searchBookByES(currentPage, pageSize, keyword);

        return bookPage;
    }
}

